Excel Power Query using M and REST

This spreadsheet uses the M-code below in Power Query to pull information from a REST API that uses pagination in it's results. The pagination cursor that is returned is unique each time the query is run. This provided a challenge as M does not easily handle unknown cursors such as this.

Providing a dynamic spreadsheet like this enables quick and efficient support for configuring POS devices as it is updated when the sheet is open with current information.

							(Cursor as text) =>
	let
		Source = Json.Document(Web.Contents("https://connect.squareup.com/v2/devices/codes?cursor="&Cursor, 
		Headers=[#"Square-Version"="2021-11-17", Authorization="Bearer XXXXXXXXXX", #"Content-Type"="application/json"]])),
	
	data = try Source[device_codes] otherwise null,
	next = try Source[cursor]